package com.mdd.admin.controller.team;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ITeamService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.competition.CompetitionApplyExamineValidate;
import com.mdd.admin.validate.team.TeamCreateValidate;
import com.mdd.admin.validate.team.TeamSearchValidate;
import com.mdd.admin.validate.team.TeamUpdateValidate;
import com.mdd.admin.vo.team.TeamDetailVo;
import com.mdd.admin.vo.team.TeamListedVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/adminapi/team")
@Api(tags = "社团管理")
public class TeamController {

    @Resource
    private ITeamService iTeamService;

    @GetMapping("/lists")
    @ApiOperation(value="社团列表")
    public AjaxResult<PageResult<TeamListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated TeamSearchValidate searchValidate) {
        PageResult<TeamListedVo> list = iTeamService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="社团详情")
    public AjaxResult<TeamDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TeamDetailVo detail = iTeamService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "社团新增")
    @PostMapping("/add")
    @ApiOperation(value="社团新增")
    public AjaxResult<Object> add(@Validated @RequestBody TeamCreateValidate createValidate) {
        iTeamService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "社团编辑")
    @PostMapping("/edit")
    @ApiOperation(value="社团编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TeamUpdateValidate updateValidate) {
        iTeamService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "社团删除")
    @PostMapping("/del")
    @ApiOperation(value="社团删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTeamService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @Log(title = "赛事申请审核")
    @PostMapping("/examine")
    @ApiOperation(value="赛事申请审核")
    public AjaxResult<Object> examine(@Validated @RequestBody CompetitionApplyExamineValidate updateValidate) {
        iTeamService.examine(updateValidate);
        return AjaxResult.success("审核成功");
    }

}
